<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/26
 * Time: 15:28
 */
namespace app\modules\api\controllers\open;

use app\models\Store;
use app\models\Admin;
use app\opening\BaseApiResponse;
use yii\data\Pagination;

class AppController extends BaseController
{
    public function actionOtherApp(){
        $query = Store::find()->alias('s')->where([
            'AND',
            ['s.is_delete' => 0],
            ['a.is_delete' => 0],
        ])->leftJoin(['a' => Admin::tableName()], 's.admin_id=a.id');
        /*if ($keyword = trim($keyword)) {
            $query->andWhere([
                'OR',
                ['LIKE', 's.name', $keyword],
                ['LIKE', 'a.username', $keyword],
            ]);
        }*/

        $count = $query->count();
        $pagination = new Pagination(['totalCount' => $count]);
        $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('acid DESC')
            ->select(['s.id AS acid','s.name','s.contact_tel','a.username'])->asArray()->all();
        $data = [
            'code' => 0,
            'msg' => 'success',
            'data' => [
                'list' => $list
            ],
        ];
        return new BaseApiResponse($data);
    }
}
